<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>测试</title>
</head>
<body>
	<script type="text/javascript">
		//json测试
		/* var JSONObject = {
			"name" : "Bill Gates",
			"street" : "Fifth Avenue New York 666",
			"age" : 56,
			"phone" : "555 1234567"
		};  */
		/* var c = 80;
		var JSONString = '{"name" : "Bill Gates","street" : "Fifth Avenue New York 666","age" : c+10,"phone" : "555 1234567"}';
		//var JSONObject = JSON.parse(JSONString);
		//console.log(JSONObject);
		
		var JSONObject2 = eval('('+JSONString+')');
		console.log(JSONObject2); */

		//js原型链
		/* var person = function(name) {
			this.name = name
		};
		person.prototype.getName = function() {
			return this.name;
		}
		var zjh = new person('zhangjiahao');
		zjh.getName(); //zhangjiahao */
		
		//js继承
		/*function Animal(type){
			this.type = type;
		}
		//apply或call
		 function Cat(name,color){
			Animal.apply(this, arguments);//第一个参数会直接覆盖父级类型的第一个参数
			this.name = name;
			this.color = color;
		} */
		//等价于
		/* function Cat(name,color){
			this.type = name;
			this.name = name;
			this.color = color;
		} */
		/* var cat1 = new Cat("大毛","黄色");
		console.log(cat1.type); //大毛
		console.log(cat1.name);//大毛
		console.log(cat1.color);//黄色 */
		
		//prototype模式
		/* function Animal(){
			Animal.prototype.species = "动物";
		}
		function Cat(name,color){
			this.name = name;
			this.color = color;
		}
		Cat.prototype = new Animal();//子对象原型赋值父对象
		Cat.prototype.constructor = Cat;//这时子对象原型构造器就是原本父对象的构造器，为了保证继承链不紊乱，要重新赋值原型构造器
		
		var cat1 = new Cat("大毛","黄色");
		console.log(cat1.constructor == Animal);
		console.log(cat1.species);//动物
		console.log(cat1.name);//大毛
		console.log(cat1.color);//黄色 */
		
		//多继承
		/* function Animal(){
			this.species = "动物";
		}
		function Felis(){
			this.fur = "很多毛";
		}
		//apply或call
		function Cat(name,color){
			Animal.apply(this, arguments);
			Felis.call(this, name, color);
			this.name = name;
			this.color = color;
		} */
		//等价于
		/* function Cat(name,color){
			this.species = "动物";
			this.fur = "很多毛";
			this.name = name;
			this.color = color;
		} */
		/* var cat1 = new Cat("大毛","黄色");
		console.log(cat1.name);//大毛
		console.log(cat1.color);//黄色
		console.log(cat1.species);//动物
		console.log(cat1.fur);//很多毛 */
		
		//js闭包
		/* function closure(){
			var a = 0;
			return function(){
				return a++;
			}
		}
		var x = closure();
		console.log(x());
		console.log(x());
		console.log(x());
		console.log(x()); */

		//js数组排重
		var arr = [1,2,3,4,1,2,5];
		function duplicateDetection(arr){
			var resultArr = [];
			for (var i = 0; i < arr.length; i++) {
				if(resultArr.indexOf(arr[i])<0){
					resultArr.push(arr[i]);
				}
			};
			return resultArr;
		}
		
		console.log(arr);
		console.log(duplicateDetection(arr));

	</script>
</body>

</html>





